<template>
	<div style="height:100%;">
		<div style="height:40px;">
			<el-button style="position:absolute;right:20px;top: 5px;" size="mini" type="primary" @click="addUseCheck" v-if="flag!='look'">添加</el-button>
      <el-button style="position:absolute;right:80px;top: 5px;" size="mini" type="primary" @click="chooseUseCheck" v-if="flag!='look'">选择</el-button>
    </div>
		<div style="height:calc(100% - 40px)">
			<el-table :data="checkData" style="width: 100%;height:100%" class="tableCon" size="mini" key="checkData" ref="standardTable">
				<el-table-column label="序号" min-width="50px">
					<template slot-scope="scope">
						{{scope.$index+1}}
					</template>
				</el-table-column>
				<el-table-column property="checkType" label="类型" min-width="100px">
					<template slot-scope="scope">
						<span v-if="scope.row.checkType === 0">测试前检查项</span>
						<span v-if="scope.row.checkType === 1">测试后检查项</span>
					</template>
				</el-table-column>
				<el-table-column property="content" label="检查项" min-width="100px">
				</el-table-column>
        <el-table-column label="操作" min-width="100px">
          <template slot-scope="scope">
          	<el-button @click="deleteRecord(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
			</el-table>
		</div>
		<div v-if="checkShow">
			<check :allCheckData.sync="allCheckData" :checkId.sync="checkId" :checkTitle.sync="checkTitle"></check>
		</div>
    <div v-if="addCheckShow">
    	<addCheck :checkId.sync="checkId" :checkTitle.sync="checkTitle"></addCheck>
    </div>
	</div>
</template>

<script>
	import check from './dialog/check' //保养计划
  import addCheck from './dialog/addCheck'
	export default {
		components: {
			check,
      addCheck
		},
		props: { beforeCheckData: Object, flag: String },
		data() {
			return {
				allCheckData: [],
				checkTitle: '',
				page: 1,
				tableHeightD: ((window.innerHeight - 300) / 3 - 25),
				checkData: [],
				checkShow: false,
				checkId: '',
        addCheckShow:false,
			}
		},
		computed: {
			tabDivHeight() {
				return (window.innerHeight - 460)
			}
		},
		mounted() {
			this.checkId = this.beforeCheckData.id
			this.init()
		},
		methods: {
			chooseUseCheck() {
				this.readPreUsecheck(this.beforeCheckData.equipmentType).then(res => {
					this.allCheckData = res.data
					this.checkTitle = '前'
					this.checkShow = true
				})

			},
			init() {
				this.$http({
					apiUrl: 'resource/readUsecheckList.htm',
					method: 'post',
					params: { id: this.beforeCheckData.id, checkType:0},
					isJson: false
				}).then(res => {
					if (res.code === 0) {
						this.checkData = res.data

					}
				})


			},
			// readUsecheckList
			readPreUsecheck(equipmentType) {
				return new Promise((resolve, reject) => {
					this.$http({
						apiUrl: 'resource/readPreUsecheck.htm',
						method: 'get',
						params: { equipmentType: equipmentType },
					}).then(res => {
						if (res.code === 0) {
							resolve(res)
						} else {
							reject('!!')
						}
					})
				})

			},
			addUseCheck(){
			  this.addCheckShow = true;
			  this.checkTitle = '前'

			},
      deleteRecord(row){
        this.$confirm('是否删除', '提示', {
        	confirmButtonText: '确定',
        	cancelButtonText: '取消',
        	type: 'warning'
        }).then(() => {
        	this.$http({
        		method: 'post',
        		apiUrl: '/resource/deleteEquipUseCheck.htm',
        		params: {id:row.id},
        		isJson: false
        	}).then(res => {
        		if (res.code == 0) {
        			this.$message({
        				type: 'success',
        				message: '删除成功'
        			})
        			this.init()
        		}
        	})
        }).catch(() => {
        	this.$message({
        		type: 'info',
        		message: '已取消删除'
        	});
        });
      },
      handleSizeChange() { },
			handleCurrentChange() { },
		}
	}

</script>

<style>

</style>
